import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [

  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue')
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('../views/UserView.vue'),
    // 路由独享守卫
    beforeEnter(to,from){
      console.log(to)
      console.log(from)
      alert("您必须登录后才能访问当前页面");
      window.location.href="/login"
    }
  },
  {
    path: '/shop',
    name: 'shop',
    component: () => import('../views/ShopView.vue')
  },
  {
    path: '/fenlei',
    name: 'fenlei',
    component: () => import('../views/FenLei.vue')
  },
  {
    // path: '/all/:xiaoming',
    path: '/all',
    name: 'all',
    component: () => import('../views/AllView.vue')
  },
  {
   
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path:"/",
    redirect:"/login"
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})



// // 全局前置守卫
// router.beforeEach((to,from,next)=>{
//   console.log(to)
//   console.log(from)
//   console.log("前置守卫")
//   next()
// })
// // 全局后置守卫
// router.afterEach((to,from)=>{
//   console.log("后置守卫")
//   console.log(to)
//   console.log(from)
// })



// router.beforeEach((to,from,next)=>{
//     if(to.path=="/login"){
//       // 如果你要去的路径是登录页面 你就正常进入
//       next()
//     }else{
//       // 不是登录页面我就不让你进入
//       alert("您必须登录后才能访问")
//       next("/login")
//     }
// })

export default router
